import json,time,os
import pandas as pd

if __name__ == '__main__':
    count_id = set([])
    for one in os.listdir('./static'):
        if '.' not in one: count_id.add(one)
    file = pd.read_excel("allrecipes.xlsx")
    for i in range(66705,0,-1):
        name = file.iloc[i]['菜名']
        if type(name) != str: continue
        name = name.replace("®","").replace(" ","\ ").replace("&#39;","'").replace("&#34;",'"').replace("(","\(").replace(")","\)").replace("'","\\'").replace('"','\\"').replace("&amp;","&")
        if str(i) not in count_id: 
            print("ls /tmp/pic-300/"+name+"*.jpg")
            files = [ item.strip() for item in os.popen("ls /tmp/pic-300/"+name+"*.jpg").read().split("\n") ]
            files = list(filter(lambda x: len(x) > 0,files))
            for j,fname in enumerate(files):
                if len(fname.strip()) == 0: continue
                if j == 0: 
                    os.system("mkdir static/%d"%i)
                    cmd = '''cp "%s" static/%d/%d.jpg'''%(fname,i,i)
                    print(cmd)
                    os.system(cmd)
                else:
                    cmd = '''cp "%s" static/%d/%d_%d.jpg'''%(fname,i,i,j)
                    print(cmd)
                    os.system(cmd)
                print(i,j,fname,"*******************")
